package com.ruoyi.pcwl.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;


import com.ruoyi.pcwl.domain.query.TravelNodeQuery;
import com.ruoyi.pcwl.domain.TravelNode;
import com.ruoyi.pcwl.mapper.TravelNodeMapper;
import com.ruoyi.pcwl.service.TravelNodeService;


/**
 * 主题旅游节点信息表 业务接口实现
 */
@Service("travelNodeService")
public class TravelNodeServiceImpl extends ServiceImpl<TravelNodeMapper, TravelNode> implements TravelNodeService {


	/**
	 * 据条件查询记录数
	 */
	@Override
	public Integer findCountByParam(TravelNodeQuery reqParam) {
		QueryWrapper<TravelNode> wrapper = new QueryWrapper<>();
		if (reqParam.getId()!=null)
			wrapper.eq("id",reqParam.getId());
		if (reqParam.getTravelGuidesId()!=null)
			wrapper.eq("travel_guides_id",reqParam.getTravelGuidesId());
		if (reqParam.getScenicSpotId()!=null)
			wrapper.eq("scenic_spot_id",reqParam.getScenicSpotId());
		if (reqParam.getArticleId()!=null)
			wrapper.eq("article_id",reqParam.getArticleId());
		if (StringUtils.isNotEmpty(reqParam.getTravelNodeName())) {
			wrapper.like("travel_node_name", reqParam.getTravelNodeName());
		}
		if (StringUtils.isNotEmpty(reqParam.getTravelNodeEnv())) {
			wrapper.like("travel_node_env", reqParam.getTravelNodeEnv());
		}
		if (StringUtils.isNotEmpty(reqParam.getTravelNodeDetails())) {
			wrapper.like("travel_node_details", reqParam.getTravelNodeDetails());
		}
		if (reqParam.getCategoryId()!=null)
			wrapper.eq("category_id",reqParam.getCategoryId());
		if (StringUtils.isNotEmpty(reqParam.getCategoryName())) {
			wrapper.like("category_name", reqParam.getCategoryName());
		}
		if (StringUtils.isNotEmpty(reqParam.getTags())) {
			wrapper.like("tags", reqParam.getTags());
		}
		if (reqParam.getHot()!=null)
			wrapper.eq("hot",reqParam.getHot());
		if (StringUtils.isNotEmpty(reqParam.getBusinessTime())) {
			wrapper.like("business_time", reqParam.getBusinessTime());
		}
		if (StringUtils.isNotEmpty(reqParam.getAddress())) {
			wrapper.like("address", reqParam.getAddress());
		}
		if (StringUtils.isNotEmpty(reqParam.getUsername())) {
			wrapper.like("username", reqParam.getUsername());
		}
		if (StringUtils.isNotEmpty(reqParam.getStatus())) {
			wrapper.like("status", reqParam.getStatus());
		}
		if (StringUtils.isNotEmpty(reqParam.getRemark())) {
			wrapper.like("remark", reqParam.getRemark());
		}
		if (StringUtils.isNotEmpty(reqParam.getUrl())) {
			wrapper.like("url", reqParam.getUrl());
		}
		if (StringUtils.isNotEmpty(reqParam.getPic())) {
			wrapper.like("pic", reqParam.getPic());
		}
		if (reqParam.getMediaFileId()!=null)
			wrapper.eq("media_file_id",reqParam.getMediaFileId());
		if (reqParam.getSort()!=null)
			wrapper.eq("sort",reqParam.getSort());
		Long aLong = baseMapper.selectCount(wrapper);
		return aLong.intValue();
	}

	/**
	 * 根据条件查询列表
	 */
	@Override
	public IPage<TravelNode> selectPage(TravelNodeQuery reqParam) {
		QueryWrapper<TravelNode> wrapper = new QueryWrapper<>();
		if (reqParam.getId()!=null)
			wrapper.eq("id",reqParam.getId());
		if (reqParam.getTravelGuidesId()!=null)
			wrapper.eq("travel_guides_id",reqParam.getTravelGuidesId());
		if (reqParam.getScenicSpotId()!=null)
			wrapper.eq("scenic_spot_id",reqParam.getScenicSpotId());
		if (reqParam.getArticleId()!=null)
			wrapper.eq("article_id",reqParam.getArticleId());
		if (StringUtils.isNotEmpty(reqParam.getTravelNodeName())) {
			wrapper.like("travel_node_name", reqParam.getTravelNodeName());
		}
		if (StringUtils.isNotEmpty(reqParam.getTravelNodeEnv())) {
			wrapper.like("travel_node_env", reqParam.getTravelNodeEnv());
		}
		if (StringUtils.isNotEmpty(reqParam.getTravelNodeDetails())) {
			wrapper.like("travel_node_details", reqParam.getTravelNodeDetails());
		}
		if (reqParam.getCategoryId()!=null)
			wrapper.eq("category_id",reqParam.getCategoryId());
		if (StringUtils.isNotEmpty(reqParam.getCategoryName())) {
			wrapper.like("category_name", reqParam.getCategoryName());
		}
		if (StringUtils.isNotEmpty(reqParam.getTags())) {
			wrapper.like("tags", reqParam.getTags());
		}
		if (reqParam.getHot()!=null)
			wrapper.eq("hot",reqParam.getHot());
		if (StringUtils.isNotEmpty(reqParam.getBusinessTime())) {
			wrapper.like("business_time", reqParam.getBusinessTime());
		}
		if (StringUtils.isNotEmpty(reqParam.getAddress())) {
			wrapper.like("address", reqParam.getAddress());
		}
		if (StringUtils.isNotEmpty(reqParam.getUsername())) {
			wrapper.like("username", reqParam.getUsername());
		}
		if (StringUtils.isNotEmpty(reqParam.getStatus())) {
			wrapper.like("status", reqParam.getStatus());
		}
		if (StringUtils.isNotEmpty(reqParam.getRemark())) {
			wrapper.like("remark", reqParam.getRemark());
		}
		if (StringUtils.isNotEmpty(reqParam.getUrl())) {
			wrapper.like("url", reqParam.getUrl());
		}
		if (StringUtils.isNotEmpty(reqParam.getPic())) {
			wrapper.like("pic", reqParam.getPic());
		}
		if (reqParam.getMediaFileId()!=null)
			wrapper.eq("media_file_id",reqParam.getMediaFileId());
		if (reqParam.getSort()!=null)
			wrapper.eq("sort",reqParam.getSort());

		if (MapUtils.isNotEmpty(reqParam.getParams()))
		{
			Map<String, Object> params = reqParam.getParams();
			if (params.keySet().contains("beginTime"))
				wrapper.ge("create_date", params.get("beginTime"));
			if (params.keySet().contains("endTime"))
				wrapper.le("create_date", params.get("endTime"));
		}

		return baseMapper.selectPage(reqParam.getPage(), wrapper);
	}

	/**
	 * 新增
	 */
	@Override
	public Integer add(TravelNode bean) {
		bean.setCreateDate(new Date());
		return baseMapper.insert(bean);
	}

	/**
	 * 批量新增
	 */
	@Override
	public Integer addBatch(List<TravelNode> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return baseMapper.insertBatch(listBean);
	}

	/**
	 * 批量新增或者修改
	 */
//	@Override
//	public Integer addOrUpdateBatch(List<TravelNode> listBean) {
//		if (listBean == null || listBean.isEmpty()) {
//			return 0;
//		}
//		return baseMapper.insertOrUpdateBatch(listBean);
//	}

	/**
	 * 多条件更新
	 */
//	@Override
//	public Integer updateByParam(TravelNode bean, TravelNodeQuery param) {
//		return baseMapper.updateByParam(bean, param);
//	}

	/**
	 * 多条件删除
	 */
//	@Override
//	public Integer deleteByParam(TravelNodeQuery param) {
//		return baseMapper.deleteByParam(param);
//	}

	/**
	 * 根据Id获取对象
	 */
	@Override
	public TravelNode getTravelNodeById(Long id) {
		return baseMapper.selectById(id);
	}

	/**
	 * 根据Id修改
	 */
	@Override
	public Integer updateTravelNodeById(TravelNode bean) {
		bean.setChangeDate(new Date());
		return baseMapper.updateById(bean);
	}

	/**
	 * 根据Id删除
	 */
	@Override
	public Integer deleteTravelNodeById(Long id) {
		return baseMapper.deleteById(id);
	}
}
